<!DOCTYPE html>
<html lang="zh-CN" data-theme="light">
  <head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width,initial-scale=1" />
    <meta name="generator" content="VuePress 2.0.0-beta.53" />
    <meta name="theme" content="VuePress Theme Hope" />
    <link rel="icon" href="/doc/images/favicon.ico"><title>掌握 GIT | AT 的文档库</title><meta name="description" content="At 的文档库，好记性不如烂笔头！">
    <style>
      :root {
        --bg-color: #fff;
      }

      html[data-theme="dark"] {
        --bg-color: #1d2025;
      }

      html,
      body {
        background: var(--bg-color);
      }
    </style>
    <script>
      const userMode = localStorage.getItem("vuepress-theme-hope-scheme");
      const systemDarkMode =
        window.matchMedia &&
        window.matchMedia("(prefers-color-scheme: dark)").matches;

      if (userMode === "dark" || (userMode !== "light" && systemDarkMode)) {
        document.querySelector("html").setAttribute("data-theme", "dark");
      }
    </script>
    <link rel="preload" href="/doc/assets/style.c3a4c10b.css" as="style" /><link rel="stylesheet" href="/doc/assets/style.c3a4c10b.css" />
    <link rel="modulepreload" href="/doc/assets/app.41440b49.js"><link rel="modulepreload" href="/doc/assets/掌握 GIT.html.724416fc.js"><link rel="modulepreload" href="/doc/assets/_plugin-vue_export-helper.cdc0426e.js"><link rel="modulepreload" href="/doc/assets/掌握 GIT.html.c150b234.js"><link rel="prefetch" href="/doc/assets/index.html.0bcc895f.js" as="script" /><link rel="prefetch" href="/doc/assets/index.html.c8df2167.js" as="script" /><link rel="prefetch" href="/doc/assets/Vue2.html.48e096c5.js" as="script" /><link rel="prefetch" href="/doc/assets/Vue3.html.324e646c.js" as="script" /><link rel="prefetch" href="/doc/assets/index.html.fb0ad0e0.js" as="script" /><link rel="prefetch" href="/doc/assets/第 1 章 导言.html.d6c662f8.js" as="script" /><link rel="prefetch" href="/doc/assets/第 2 章 TypeScript 概述.html.e976154a.js" as="script" /><link rel="prefetch" href="/doc/assets/第 3 章 类型全解.html.e4f1b931.js" as="script" /><link rel="prefetch" href="/doc/assets/第 4 章 函数.html.701a2968.js" as="script" /><link rel="prefetch" href="/doc/assets/第 5 章 类和接口.html.8988d546.js" as="script" /><link rel="prefetch" href="/doc/assets/第 6 章 类型进阶.html.45b313e3.js" as="script" /><link rel="prefetch" href="/doc/assets/index.html.a9dd6465.js" as="script" /><link rel="prefetch" href="/doc/assets/index.html.a3374cf8.js" as="script" /><link rel="prefetch" href="/doc/assets/面试题详解.html.c326eaaf.js" as="script" /><link rel="prefetch" href="/doc/assets/index.html.88582229.js" as="script" /><link rel="prefetch" href="/doc/assets/常见问题.html.e0f65550.js" as="script" /><link rel="prefetch" href="/doc/assets/扩展使用.html.87cccc41.js" as="script" /><link rel="prefetch" href="/doc/assets/index.html.a3c2858b.js" as="script" /><link rel="prefetch" href="/doc/assets/面试题详解.html.9a53d157.js" as="script" /><link rel="prefetch" href="/doc/assets/index.html.101afd82.js" as="script" /><link rel="prefetch" href="/doc/assets/面试题详解.html.8224e1cd.js" as="script" /><link rel="prefetch" href="/doc/assets/index.html.54b5ca2d.js" as="script" /><link rel="prefetch" href="/doc/assets/基础掌握.html.d839cc53.js" as="script" /><link rel="prefetch" href="/doc/assets/index.html.80e4d5cc.js" as="script" /><link rel="prefetch" href="/doc/assets/基础掌握.html.9a178a04.js" as="script" /><link rel="prefetch" href="/doc/assets/扩展知识.html.3535ab30.js" as="script" /><link rel="prefetch" href="/doc/assets/项目搭建.html.e926587b.js" as="script" /><link rel="prefetch" href="/doc/assets/index.html.881e95b0.js" as="script" /><link rel="prefetch" href="/doc/assets/安装及使用.html.ba7314a3.js" as="script" /><link rel="prefetch" href="/doc/assets/index.html.f9509ce0.js" as="script" /><link rel="prefetch" href="/doc/assets/第 1 章.html.726a0bb9.js" as="script" /><link rel="prefetch" href="/doc/assets/第 2 章.html.38f55e7d.js" as="script" /><link rel="prefetch" href="/doc/assets/Controllers.html.6b27764c.js" as="script" /><link rel="prefetch" href="/doc/assets/Module.html.3849b10b.js" as="script" /><link rel="prefetch" href="/doc/assets/Providers.html.7d2793f1.js" as="script" /><link rel="prefetch" href="/doc/assets/404.html.c5de7dd9.js" as="script" /><link rel="prefetch" href="/doc/assets/index.html.86b08b0b.js" as="script" /><link rel="prefetch" href="/doc/assets/index.html.f4119260.js" as="script" /><link rel="prefetch" href="/doc/assets/Vue2.html.caf7eb18.js" as="script" /><link rel="prefetch" href="/doc/assets/Vue3.html.6dc23cf4.js" as="script" /><link rel="prefetch" href="/doc/assets/index.html.868f2c80.js" as="script" /><link rel="prefetch" href="/doc/assets/第 1 章 导言.html.9edf000e.js" as="script" /><link rel="prefetch" href="/doc/assets/第 2 章 TypeScript 概述.html.76b27e4d.js" as="script" /><link rel="prefetch" href="/doc/assets/第 3 章 类型全解.html.9ad8a3d4.js" as="script" /><link rel="prefetch" href="/doc/assets/第 4 章 函数.html.9115df00.js" as="script" /><link rel="prefetch" href="/doc/assets/第 5 章 类和接口.html.e392a0d1.js" as="script" /><link rel="prefetch" href="/doc/assets/第 6 章 类型进阶.html.1b5b864e.js" as="script" /><link rel="prefetch" href="/doc/assets/index.html.e5a75968.js" as="script" /><link rel="prefetch" href="/doc/assets/index.html.974654cf.js" as="script" /><link rel="prefetch" href="/doc/assets/面试题详解.html.ed3fa7a3.js" as="script" /><link rel="prefetch" href="/doc/assets/index.html.3b9ebcaa.js" as="script" /><link rel="prefetch" href="/doc/assets/常见问题.html.b427e39a.js" as="script" /><link rel="prefetch" href="/doc/assets/扩展使用.html.76b3dd90.js" as="script" /><link rel="prefetch" href="/doc/assets/index.html.8b55f9ef.js" as="script" /><link rel="prefetch" href="/doc/assets/面试题详解.html.8ee968a7.js" as="script" /><link rel="prefetch" href="/doc/assets/index.html.06371751.js" as="script" /><link rel="prefetch" href="/doc/assets/面试题详解.html.6b672044.js" as="script" /><link rel="prefetch" href="/doc/assets/index.html.b200eaff.js" as="script" /><link rel="prefetch" href="/doc/assets/基础掌握.html.5135d2c4.js" as="script" /><link rel="prefetch" href="/doc/assets/index.html.557b7bf5.js" as="script" /><link rel="prefetch" href="/doc/assets/基础掌握.html.7b535b09.js" as="script" /><link rel="prefetch" href="/doc/assets/扩展知识.html.c6b233af.js" as="script" /><link rel="prefetch" href="/doc/assets/项目搭建.html.450f0b1d.js" as="script" /><link rel="prefetch" href="/doc/assets/index.html.6483ed06.js" as="script" /><link rel="prefetch" href="/doc/assets/安装及使用.html.b4d859f3.js" as="script" /><link rel="prefetch" href="/doc/assets/index.html.f15cf3e9.js" as="script" /><link rel="prefetch" href="/doc/assets/第 1 章.html.127b1e7c.js" as="script" /><link rel="prefetch" href="/doc/assets/第 2 章.html.ea8e67e2.js" as="script" /><link rel="prefetch" href="/doc/assets/Controllers.html.029df1e7.js" as="script" /><link rel="prefetch" href="/doc/assets/Module.html.f102db2a.js" as="script" /><link rel="prefetch" href="/doc/assets/Providers.html.9bef3753.js" as="script" /><link rel="prefetch" href="/doc/assets/404.html.2cfd6b20.js" as="script" /><link rel="prefetch" href="/doc/assets/photoswipe.esm.09e03fed.js" as="script" />
  </head>
  <body>
    <div id="app"><!--[--><!--[--><!--[--><span tabindex="-1"></span><a href="#main-content" class="skip-link sr-only">Skip to content</a><!--]--><div class="theme-container has-toc"><!--[--><!--[--><header class="navbar"><div class="navbar-left"><button class="toggle-sidebar-button" title="Toggle Sidebar"><span class="icon"></span></button><!--[--><!----><!--]--><a href="/doc/" class="brand"><!----><!----><span class="site-name">AT 的文档库</span></a><!--[--><!----><!--]--></div><div class="navbar-center"><!--[--><!----><!--]--><nav class="nav-links"><div class="nav-item hide-in-mobile"><a href="/doc/" class="nav-link" aria-label="首页"><!---->首页<!----></a></div><div class="nav-item hide-in-mobile"><div class="dropdown-wrapper"><button class="dropdown-title" type="button" aria-label="开发问题汇总"><span class="title"><!---->开发问题汇总</span><span class="arrow"></span><ul class="nav-dropdown"><li class="dropdown-item"><a href="/doc/development-question/Vue" class="nav-link" aria-label="Vue"><!---->Vue<!----></a></li></ul></button></div></div><div class="nav-item hide-in-mobile"><div class="dropdown-wrapper"><button class="dropdown-title" type="button" aria-label="系统笔记"><span class="title"><!---->系统笔记</span><span class="arrow"></span><ul class="nav-dropdown"><li class="dropdown-item"><a aria-current="page" href="/doc/sysnotes/Git/%E6%8E%8C%E6%8F%A1%20GIT.html" class="router-link-active router-link-exact-active nav-link active" aria-label="GIT"><!---->GIT<!----></a></li><li class="dropdown-item"><a href="/doc/sysnotes/Nvm/%E5%AE%89%E8%A3%85%E5%8F%8A%E4%BD%BF%E7%94%A8.html" class="nav-link" aria-label="NVM"><!---->NVM<!----></a></li><li class="dropdown-item"><a href="/doc/sysnotes/Linux/%E5%9F%BA%E7%A1%80%E6%8E%8C%E6%8F%A1.html" class="nav-link" aria-label="Linux"><!---->Linux<!----></a></li><li class="dropdown-item"><a href="/doc/sysnotes/JavaScript" class="nav-link" aria-label="JavaScript"><!---->JavaScript<!----></a></li><li class="dropdown-item"><a href="/doc/sysnotes/CSS" class="nav-link" aria-label="CSS"><!---->CSS<!----></a></li><li class="dropdown-item"><a href="/doc/sysnotes/HTML" class="nav-link" aria-label="HTML"><!---->HTML<!----></a></li></ul></button></div></div><div class="nav-item hide-in-mobile"><div class="dropdown-wrapper"><button class="dropdown-title" type="button" aria-label="阅读笔记"><span class="title"><!---->阅读笔记</span><span class="arrow"></span><ul class="nav-dropdown"><li class="dropdown-item"><a href="/doc/readbook/《Vue.js 设计与实现》/" class="nav-link" aria-label="《Vue.js 设计与实现》"><!---->《Vue.js 设计与实现》<!----></a></li><li class="dropdown-item"><a href="/doc/readbook/《TypeScript 编程》/" class="nav-link" aria-label="《TypeScript 编程》"><!---->《TypeScript 编程》<!----></a></li></ul></button></div></div></nav><!--[--><!----><!--]--></div><div class="navbar-right"><!--[--><!----><!--]--><div class="nav-item hide-in-mobile"><button id="appearance-switch"><svg xmlns="http://www.w3.org/2000/svg" class="icon auto-icon" viewBox="0 0 1024 1024" fill="currentColor" aria-label="auto icon" style="display:block;"><path d="M512 992C246.92 992 32 777.08 32 512S246.92 32 512 32s480 214.92 480 480-214.92 480-480 480zm0-840c-198.78 0-360 161.22-360 360 0 198.84 161.22 360 360 360s360-161.16 360-360c0-198.78-161.22-360-360-360zm0 660V212c165.72 0 300 134.34 300 300 0 165.72-134.28 300-300 300z"></path></svg><svg xmlns="http://www.w3.org/2000/svg" class="icon dark-icon" viewBox="0 0 1024 1024" fill="currentColor" aria-label="dark icon" style="display:none;"><path d="M524.8 938.667h-4.267a439.893 439.893 0 0 1-313.173-134.4 446.293 446.293 0 0 1-11.093-597.334A432.213 432.213 0 0 1 366.933 90.027a42.667 42.667 0 0 1 45.227 9.386 42.667 42.667 0 0 1 10.24 42.667 358.4 358.4 0 0 0 82.773 375.893 361.387 361.387 0 0 0 376.747 82.774 42.667 42.667 0 0 1 54.187 55.04 433.493 433.493 0 0 1-99.84 154.88 438.613 438.613 0 0 1-311.467 128z"></path></svg><svg xmlns="http://www.w3.org/2000/svg" class="icon light-icon" viewBox="0 0 1024 1024" fill="currentColor" aria-label="light icon" style="display:none;"><path d="M952 552h-80a40 40 0 0 1 0-80h80a40 40 0 0 1 0 80zM801.88 280.08a41 41 0 0 1-57.96-57.96l57.96-58a41.04 41.04 0 0 1 58 58l-58 57.96zM512 752a240 240 0 1 1 0-480 240 240 0 0 1 0 480zm0-560a40 40 0 0 1-40-40V72a40 40 0 0 1 80 0v80a40 40 0 0 1-40 40zm-289.88 88.08-58-57.96a41.04 41.04 0 0 1 58-58l57.96 58a41 41 0 0 1-57.96 57.96zM192 512a40 40 0 0 1-40 40H72a40 40 0 0 1 0-80h80a40 40 0 0 1 40 40zm30.12 231.92a41 41 0 0 1 57.96 57.96l-57.96 58a41.04 41.04 0 0 1-58-58l58-57.96zM512 832a40 40 0 0 1 40 40v80a40 40 0 0 1-80 0v-80a40 40 0 0 1 40-40zm289.88-88.08 58 57.96a41.04 41.04 0 0 1-58 58l-57.96-58a41 41 0 0 1 57.96-57.96z"></path></svg></button></div><form class="search-box" role="search"><input type="search" autocomplete="off" spellcheck="false" value><!----></form><!--[--><!----><!--]--><button class="toggle-navbar-button" aria-label="Toggle Navbar" aria-expanded="false" aria-controls="nav-screen"><span class="button-container"><span class="button-top"></span><span class="button-middle"></span><span class="button-bottom"></span></span></button></div></header><!----><!--]--><!----><div class="toggle-sidebar-wrapper"><span class="arrow left"></span></div><aside class="sidebar"><!--[--><!----><!--]--><ul class="sidebar-links"><li><section class="sidebar-group"><button class="sidebar-heading clickable"><!----><span class="title">CSS</span><span class="arrow right"></span></button><!----></section></li><li><section class="sidebar-group"><button class="sidebar-heading clickable active"><!----><span class="title">GIT</span><span class="arrow down"></span></button><ul class="sidebar-links"><li><!--[--><a aria-current="page" href="/doc/sysnotes/Git/%E6%8E%8C%E6%8F%A1%20GIT.html" class="router-link-active router-link-exact-active nav-link active sidebar-link sidebar-page active" aria-label="掌握 GIT"><!---->掌握 GIT<!----></a><ul class="sidebar-sub-headers"><li class="sidebar-sub-header"><a aria-current="page" href="/doc/sysnotes/Git/%E6%8E%8C%E6%8F%A1%20GIT.html#初始配置" class="router-link-active router-link-exact-active nav-link sidebar-link heading" aria-label="初始配置"><!---->初始配置<!----></a><ul class="sidebar-sub-headers"></ul></li><li class="sidebar-sub-header"><a aria-current="page" href="/doc/sysnotes/Git/%E6%8E%8C%E6%8F%A1%20GIT.html#入门" class="router-link-active router-link-exact-active nav-link sidebar-link heading" aria-label="入门"><!---->入门<!----></a><ul class="sidebar-sub-headers"><li class="sidebar-sub-header"><a aria-current="page" href="/doc/sysnotes/Git/%E6%8E%8C%E6%8F%A1%20GIT.html#基本命令" class="router-link-active router-link-exact-active nav-link sidebar-link heading" aria-label="基本命令"><!---->基本命令<!----></a><ul class="sidebar-sub-headers"></ul></li></ul></li><li class="sidebar-sub-header"><a aria-current="page" href="/doc/sysnotes/Git/%E6%8E%8C%E6%8F%A1%20GIT.html#工作区" class="router-link-active router-link-exact-active nav-link sidebar-link heading" aria-label="工作区"><!---->工作区<!----></a><ul class="sidebar-sub-headers"></ul></li><li class="sidebar-sub-header"><a aria-current="page" href="/doc/sysnotes/Git/%E6%8E%8C%E6%8F%A1%20GIT.html#暂存区" class="router-link-active router-link-exact-active nav-link sidebar-link heading" aria-label="暂存区"><!---->暂存区<!----></a><ul class="sidebar-sub-headers"></ul></li><li class="sidebar-sub-header"><a aria-current="page" href="/doc/sysnotes/Git/%E6%8E%8C%E6%8F%A1%20GIT.html#日志" class="router-link-active router-link-exact-active nav-link sidebar-link heading" aria-label="日志"><!---->日志<!----></a><ul class="sidebar-sub-headers"></ul></li><li class="sidebar-sub-header"><a aria-current="page" href="/doc/sysnotes/Git/%E6%8E%8C%E6%8F%A1%20GIT.html#分支" class="router-link-active router-link-exact-active nav-link sidebar-link heading" aria-label="分支"><!---->分支<!----></a><ul class="sidebar-sub-headers"></ul></li><li class="sidebar-sub-header"><a aria-current="page" href="/doc/sysnotes/Git/%E6%8E%8C%E6%8F%A1%20GIT.html#reset" class="router-link-active router-link-exact-active nav-link sidebar-link heading" aria-label="reset"><!---->reset<!----></a><ul class="sidebar-sub-headers"><li class="sidebar-sub-header"><a aria-current="page" href="/doc/sysnotes/Git/%E6%8E%8C%E6%8F%A1%20GIT.html#可选参数" class="router-link-active router-link-exact-active nav-link sidebar-link heading" aria-label="可选参数"><!---->可选参数<!----></a><ul class="sidebar-sub-headers"></ul></li></ul></li><li class="sidebar-sub-header"><a aria-current="page" href="/doc/sysnotes/Git/%E6%8E%8C%E6%8F%A1%20GIT.html#定义别名" class="router-link-active router-link-exact-active nav-link sidebar-link heading" aria-label="定义别名"><!---->定义别名<!----></a><ul class="sidebar-sub-headers"><li class="sidebar-sub-header"><a aria-current="page" href="/doc/sysnotes/Git/%E6%8E%8C%E6%8F%A1%20GIT.html#git-配置文件中-gitconfig" class="router-link-active router-link-exact-active nav-link sidebar-link heading" aria-label="git 配置文件中 ~/.gitconfig"><!---->git 配置文件中 ~/.gitconfig<!----></a><ul class="sidebar-sub-headers"></ul></li><li class="sidebar-sub-header"><a aria-current="page" href="/doc/sysnotes/Git/%E6%8E%8C%E6%8F%A1%20GIT.html#环境变量" class="router-link-active router-link-exact-active nav-link sidebar-link heading" aria-label="环境变量"><!---->环境变量<!----></a><ul class="sidebar-sub-headers"></ul></li></ul></li><li class="sidebar-sub-header"><a aria-current="page" href="/doc/sysnotes/Git/%E6%8E%8C%E6%8F%A1%20GIT.html#忽略文件-gitignore" class="router-link-active router-link-exact-active nav-link sidebar-link heading" aria-label="忽略文件 .gitignore"><!---->忽略文件 .gitignore<!----></a><ul class="sidebar-sub-headers"></ul></li><li class="sidebar-sub-header"><a aria-current="page" href="/doc/sysnotes/Git/%E6%8E%8C%E6%8F%A1%20GIT.html#暂存-stash" class="router-link-active router-link-exact-active nav-link sidebar-link heading" aria-label="暂存 stash"><!---->暂存 stash<!----></a><ul class="sidebar-sub-headers"></ul></li><li class="sidebar-sub-header"><a aria-current="page" href="/doc/sysnotes/Git/%E6%8E%8C%E6%8F%A1%20GIT.html#标签-tag" class="router-link-active router-link-exact-active nav-link sidebar-link heading" aria-label="标签 Tag"><!---->标签 Tag<!----></a><ul class="sidebar-sub-headers"></ul></li><li class="sidebar-sub-header"><a aria-current="page" href="/doc/sysnotes/Git/%E6%8E%8C%E6%8F%A1%20GIT.html#打包成-zip" class="router-link-active router-link-exact-active nav-link sidebar-link heading" aria-label="打包成 zip"><!---->打包成 zip<!----></a><ul class="sidebar-sub-headers"></ul></li><li class="sidebar-sub-header"><a aria-current="page" href="/doc/sysnotes/Git/%E6%8E%8C%E6%8F%A1%20GIT.html#ssh-秘钥" class="router-link-active router-link-exact-active nav-link sidebar-link heading" aria-label="SSH 秘钥"><!---->SSH 秘钥<!----></a><ul class="sidebar-sub-headers"><li class="sidebar-sub-header"><a aria-current="page" href="/doc/sysnotes/Git/%E6%8E%8C%E6%8F%A1%20GIT.html#生成秘钥" class="router-link-active router-link-exact-active nav-link sidebar-link heading" aria-label="生成秘钥"><!---->生成秘钥<!----></a><ul class="sidebar-sub-headers"></ul></li></ul></li><li class="sidebar-sub-header"><a aria-current="page" href="/doc/sysnotes/Git/%E6%8E%8C%E6%8F%A1%20GIT.html#远程仓库" class="router-link-active router-link-exact-active nav-link sidebar-link heading" aria-label="远程仓库"><!---->远程仓库<!----></a><ul class="sidebar-sub-headers"></ul></li><li class="sidebar-sub-header"><a aria-current="page" href="/doc/sysnotes/Git/%E6%8E%8C%E6%8F%A1%20GIT.html#pull" class="router-link-active router-link-exact-active nav-link sidebar-link heading" aria-label="pull"><!---->pull<!----></a><ul class="sidebar-sub-headers"></ul></li><li class="sidebar-sub-header"><a aria-current="page" href="/doc/sysnotes/Git/%E6%8E%8C%E6%8F%A1%20GIT.html#push" class="router-link-active router-link-exact-active nav-link sidebar-link heading" aria-label="push"><!---->push<!----></a><ul class="sidebar-sub-headers"></ul></li></ul><!--]--></li><li><!--[--><a href="/doc/sysnotes/Git/%E6%89%A9%E5%B1%95%E4%BD%BF%E7%94%A8.html" class="nav-link sidebar-link sidebar-page" aria-label="扩展使用"><!---->扩展使用<!----></a><ul class="sidebar-sub-headers"></ul><!--]--></li><li><!--[--><a href="/doc/sysnotes/Git/%E5%B8%B8%E8%A7%81%E9%97%AE%E9%A2%98.html" class="nav-link sidebar-link sidebar-page" aria-label="常见问题"><!---->常见问题<!----></a><ul class="sidebar-sub-headers"></ul><!--]--></li></ul></section></li><li><section class="sidebar-group"><button class="sidebar-heading clickable"><!----><span class="title">HTML</span><span class="arrow right"></span></button><!----></section></li><li><section class="sidebar-group"><button class="sidebar-heading clickable"><!----><span class="title">JavaScript</span><span class="arrow right"></span></button><!----></section></li><li><section class="sidebar-group"><button class="sidebar-heading clickable"><!----><span class="title">Linux</span><span class="arrow right"></span></button><!----></section></li><li><section class="sidebar-group"><button class="sidebar-heading clickable"><!----><span class="title">NestJs</span><span class="arrow right"></span></button><!----></section></li><li><section class="sidebar-group"><button class="sidebar-heading clickable"><!----><span class="title">NVM</span><span class="arrow right"></span></button><!----></section></li></ul><!--[--><!----><!--]--></aside><!--[--><main class="page" id="main-content"><!--[--><!----><nav class="breadcrumb disable"></nav><div class="page-title"><h1><!---->掌握 GIT</h1><div class="page-info"><!----><!----><!----><!----><!----><span class="reading-time-info" aria-label="阅读时间⌛" data-balloon-pos="down"><svg xmlns="http://www.w3.org/2000/svg" class="icon timer-icon" viewBox="0 0 1024 1024" fill="currentColor" aria-label="timer icon"><path d="M799.387 122.15c4.402-2.978 7.38-7.897 7.38-13.463v-1.165c0-8.933-7.38-16.312-16.312-16.312H256.33c-8.933 0-16.311 7.38-16.311 16.312v1.165c0 5.825 2.977 10.874 7.637 13.592 4.143 194.44 97.22 354.963 220.201 392.763-122.204 37.542-214.893 196.511-220.2 389.397-4.661 5.049-7.638 11.651-7.638 19.03v5.825h566.49v-5.825c0-7.379-2.849-13.981-7.509-18.9-5.049-193.016-97.867-351.985-220.2-389.527 123.24-37.67 216.446-198.453 220.588-392.892zM531.16 450.445v352.632c117.674 1.553 211.787 40.778 211.787 88.676H304.097c0-48.286 95.149-87.382 213.728-88.676V450.445c-93.077-3.107-167.901-81.297-167.901-177.093 0-8.803 6.99-15.793 15.793-15.793 8.803 0 15.794 6.99 15.794 15.793 0 80.261 63.69 145.635 142.01 145.635s142.011-65.374 142.011-145.635c0-8.803 6.99-15.793 15.794-15.793s15.793 6.99 15.793 15.793c0 95.019-73.789 172.82-165.96 177.093z"></path></svg><span>大约 5 分钟</span><meta property="timeRequired" content="PT5M"></span></div><hr></div><div class="toc-place-holder"><aside id="toc"><div class="toc-header">此页内容</div><div class="toc-wrapper"><ul class="toc-list"><!--[--><li class="toc-item"><a aria-current="page" href="/doc/sysnotes/Git/%E6%8E%8C%E6%8F%A1%20GIT.html#初始配置" class="router-link-active router-link-exact-active toc-link level2">初始配置</a></li><!----><!--]--><!--[--><li class="toc-item"><a aria-current="page" href="/doc/sysnotes/Git/%E6%8E%8C%E6%8F%A1%20GIT.html#入门" class="router-link-active router-link-exact-active toc-link level2">入门</a></li><ul class="toc-list"><!--[--><li class="toc-item"><a aria-current="page" href="/doc/sysnotes/Git/%E6%8E%8C%E6%8F%A1%20GIT.html#基本命令" class="router-link-active router-link-exact-active toc-link level3">基本命令</a></li><!----><!--]--></ul><!--]--><!--[--><li class="toc-item"><a aria-current="page" href="/doc/sysnotes/Git/%E6%8E%8C%E6%8F%A1%20GIT.html#工作区" class="router-link-active router-link-exact-active toc-link level2">工作区</a></li><!----><!--]--><!--[--><li class="toc-item"><a aria-current="page" href="/doc/sysnotes/Git/%E6%8E%8C%E6%8F%A1%20GIT.html#暂存区" class="router-link-active router-link-exact-active toc-link level2">暂存区</a></li><!----><!--]--><!--[--><li class="toc-item"><a aria-current="page" href="/doc/sysnotes/Git/%E6%8E%8C%E6%8F%A1%20GIT.html#日志" class="router-link-active router-link-exact-active toc-link level2">日志</a></li><!----><!--]--><!--[--><li class="toc-item"><a aria-current="page" href="/doc/sysnotes/Git/%E6%8E%8C%E6%8F%A1%20GIT.html#分支" class="router-link-active router-link-exact-active toc-link level2">分支</a></li><!----><!--]--><!--[--><li class="toc-item"><a aria-current="page" href="/doc/sysnotes/Git/%E6%8E%8C%E6%8F%A1%20GIT.html#reset" class="router-link-active router-link-exact-active toc-link level2">reset</a></li><ul class="toc-list"><!--[--><li class="toc-item"><a aria-current="page" href="/doc/sysnotes/Git/%E6%8E%8C%E6%8F%A1%20GIT.html#可选参数" class="router-link-active router-link-exact-active toc-link level3">可选参数</a></li><!----><!--]--></ul><!--]--><!--[--><li class="toc-item"><a aria-current="page" href="/doc/sysnotes/Git/%E6%8E%8C%E6%8F%A1%20GIT.html#定义别名" class="router-link-active router-link-exact-active toc-link level2">定义别名</a></li><ul class="toc-list"><!--[--><li class="toc-item"><a aria-current="page" href="/doc/sysnotes/Git/%E6%8E%8C%E6%8F%A1%20GIT.html#git-配置文件中-gitconfig" class="router-link-active router-link-exact-active toc-link level3">git 配置文件中 ~/.gitconfig</a></li><!----><!--]--><!--[--><li class="toc-item"><a aria-current="page" href="/doc/sysnotes/Git/%E6%8E%8C%E6%8F%A1%20GIT.html#环境变量" class="router-link-active router-link-exact-active toc-link level3">环境变量</a></li><!----><!--]--></ul><!--]--><!--[--><li class="toc-item"><a aria-current="page" href="/doc/sysnotes/Git/%E6%8E%8C%E6%8F%A1%20GIT.html#忽略文件-gitignore" class="router-link-active router-link-exact-active toc-link level2">忽略文件 .gitignore</a></li><!----><!--]--><!--[--><li class="toc-item"><a aria-current="page" href="/doc/sysnotes/Git/%E6%8E%8C%E6%8F%A1%20GIT.html#暂存-stash" class="router-link-active router-link-exact-active toc-link level2">暂存 stash</a></li><!----><!--]--><!--[--><li class="toc-item"><a aria-current="page" href="/doc/sysnotes/Git/%E6%8E%8C%E6%8F%A1%20GIT.html#标签-tag" class="router-link-active router-link-exact-active toc-link level2">标签 Tag</a></li><!----><!--]--><!--[--><li class="toc-item"><a aria-current="page" href="/doc/sysnotes/Git/%E6%8E%8C%E6%8F%A1%20GIT.html#打包成-zip" class="router-link-active router-link-exact-active toc-link level2">打包成 zip</a></li><!----><!--]--><!--[--><li class="toc-item"><a aria-current="page" href="/doc/sysnotes/Git/%E6%8E%8C%E6%8F%A1%20GIT.html#ssh-秘钥" class="router-link-active router-link-exact-active toc-link level2">SSH 秘钥</a></li><ul class="toc-list"><!--[--><li class="toc-item"><a aria-current="page" href="/doc/sysnotes/Git/%E6%8E%8C%E6%8F%A1%20GIT.html#生成秘钥" class="router-link-active router-link-exact-active toc-link level3">生成秘钥</a></li><!----><!--]--></ul><!--]--><!--[--><li class="toc-item"><a aria-current="page" href="/doc/sysnotes/Git/%E6%8E%8C%E6%8F%A1%20GIT.html#远程仓库" class="router-link-active router-link-exact-active toc-link level2">远程仓库</a></li><!----><!--]--><!--[--><li class="toc-item"><a aria-current="page" href="/doc/sysnotes/Git/%E6%8E%8C%E6%8F%A1%20GIT.html#pull" class="router-link-active router-link-exact-active toc-link level2">pull</a></li><!----><!--]--><!--[--><li class="toc-item"><a aria-current="page" href="/doc/sysnotes/Git/%E6%8E%8C%E6%8F%A1%20GIT.html#push" class="router-link-active router-link-exact-active toc-link level2">push</a></li><!----><!--]--></ul></div></aside></div><!----><div class="theme-hope-content"><h1 id="掌握-git" tabindex="-1"><a class="header-anchor" href="#掌握-git" aria-hidden="true">#</a> 掌握 GIT</h1><h2 id="初始配置" tabindex="-1"><a class="header-anchor" href="#初始配置" aria-hidden="true">#</a> 初始配置</h2><p>配置文件的位置 <code>~/.gitconfig</code>，第一次执行任何 Git 命令时会自动创建 <code>.gitconfig</code> 文件。</p><p>配置基本信息:</p><div class="language-javascript line-numbers-mode" data-ext="js"><pre class="language-javascript"><code>    git config <span class="token operator">--</span>global user<span class="token punctuation">.</span>name <span class="token string">&#39;AT&#39;</span>  <span class="token comment">// 配置用户名</span>
    git config <span class="token operator">--</span>global user<span class="token punctuation">.</span>email <span class="token string">&#39;at_emailbox@163.com&#39;</span> <span class="token comment">// 配置账户邮箱</span>
</code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div><div class="line-number"></div></div></div><h2 id="入门" tabindex="-1"><a class="header-anchor" href="#入门" aria-hidden="true">#</a> 入门</h2><h3 id="基本命令" tabindex="-1"><a class="header-anchor" href="#基本命令" aria-hidden="true">#</a> 基本命令</h3><table><thead><tr><th>命令</th><th>解析</th></tr></thead><tbody><tr><td>git init</td><td>初始化仓库</td></tr><tr><td>git clone url</td><td>克隆仓库</td></tr><tr><td>git clone -b [branch] url</td><td>克隆指定分支代码</td></tr><tr><td>git status</td><td>查看状态</td></tr><tr><td>git add xxx.html</td><td>提交单个文件</td></tr><tr><td>git add .</td><td>提交所有文件</td></tr><tr><td>git commit -m &#39;xxxx&#39;</td><td>提交到仓库中</td></tr><tr><td>git commit -a -m &#39;xxxx&#39;</td><td>提交已经跟踪过的文件，不需要执行 add</td></tr><tr><td>git rm xxx.html</td><td>删除版本库与项目目录中的文件</td></tr><tr><td>git rm --cached xxx.html</td><td>只删除版本库中文件</td></tr><tr><td>git commit --amend</td><td>修改最后一次提交</td></tr></tbody></table><h2 id="工作区" tabindex="-1"><a class="header-anchor" href="#工作区" aria-hidden="true">#</a> 工作区</h2><p><code>git clean</code> 命令用来从工作目录中删除所有没有跟踪过得代码</p><ul><li><code>git clean -n</code> 会提示那些文件被删除</li><li><code>git clean -f</code> 删除当前目录中没有被跟踪过得文件，不会删除 <code>.gitignore</code> 指定的文件</li><li><code>git clean -df</code> 删除当前目录中没有被 tracked 过得文件和文件夹</li><li><code>git checkout .</code> 将没有放入到暂存区的所有文件恢复，执行后恢复到上一次提交前的状态</li><li><code>git checkout xxx</code> 放弃指定文件修改，执行后恢复到上一次提交前的状态</li><li><code>git checkout -- xxx</code> 将文件从暂存区恢复（如果没有提交到暂存区，将恢复到最近一次提交状态）</li></ul><h2 id="暂存区" tabindex="-1"><a class="header-anchor" href="#暂存区" aria-hidden="true">#</a> 暂存区</h2><ul><li><code>git add .</code> 提交所有文件（修改、新增）到暂存区</li><li><code>git add -u</code> 提交修改文件不提交新文件</li><li><code>git ls-files -s</code> 查看暂存区文件列表</li><li><code>git cat-file -p 散列值</code> 查看暂存区文件内容</li><li><code>git reset</code> 撤销上次提交</li></ul><h2 id="日志" tabindex="-1"><a class="header-anchor" href="#日志" aria-hidden="true">#</a> 日志</h2><ul><li><code>git log</code> 查看日志</li><li><code>git log -p -2</code> 查看最近两次提交日志并显示文件差异</li><li><code>git log --name-only</code> 显示已修改的文件清单</li><li><code>git log --name-status</code> 显示新增、修改、删除的文件</li><li><code>git log --oneline</code> 一行显示并只显示 SHA-1 的前几个字符</li><li><code>git log --graph --pretty=format:&#39;%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)&lt;%an&gt;%Creset&#39; --abbrev-commit</code> 自定义日志信息：如下图</li></ul><p><img src="/doc/assets/git-log-curstom.c607c2a3.png" alt="git log"></p><h2 id="分支" tabindex="-1"><a class="header-anchor" href="#分支" aria-hidden="true">#</a> 分支</h2><ul><li><code>git branch dev</code> 创建 dev 分支</li><li><code>git branch [-a]</code> 查看分支加上 -a 可展示远程分支</li><li><code>git checkout dev</code> 切换到 dev 分支</li><li><code>git checkout -b dev</code> 创建 dev 分支的同时切换到 dev 分支</li><li><code>git branch -m main master</code> 将 main 分支名改为 master</li><li><code>git checkout dev | git merge master</code> 在 dev 分支上 合并 master 的分支</li><li><code>git branch -d dev</code> 删除本地 dev 分支</li><li><code>git push origin :dev</code> 删除远程 dev 分支</li><li><code>git branch --no-merged</code> 查看未合并当前分支代码的其他分支</li><li><code>git branch --merged</code> 查看已合并当前分支的其他分支</li></ul><h2 id="reset" tabindex="-1"><a class="header-anchor" href="#reset" aria-hidden="true">#</a> reset</h2><blockquote><p>使用 reset 可以恢复到历史提交点，重置暂存区与工作目录的内容</p></blockquote><h3 id="可选参数" tabindex="-1"><a class="header-anchor" href="#可选参数" aria-hidden="true">#</a> 可选参数</h3><ul><li>--hard 重置的同时，直接将 working tree 工作目录、index 暂存区 及 repository 仓库都重置成 reset 目标节点的内容</li><li>--soft 重置的同时，保留工作目录和暂存区的内容，只让仓库中的内容和 reset 目标节点内容一致</li><li>--mixed (默认选项) 重置的同时，只保留工作目录的内容，将暂存区和仓库中的内容重置成 reset 目标节点的内容</li></ul><h4 id="使用" tabindex="-1"><a class="header-anchor" href="#使用" aria-hidden="true">#</a> 使用</h4><ul><li><code>git reset</code> 将 add 到暂存区的内容回退</li><li><code>git reset --hard 9a122b7233eb653f3effc1773f1e962815e968e8</code> 回退到指定提交版本，重置 stage 和工作区的内容</li><li><code>git reset --hard HEAD^^^</code> 恢复前三个版本</li><li><code>git reset --soft</code> 保留工作区内容，只回退 commit。工作目录和暂存区内容一致，仓库内容重置</li><li><code>git reset HEAD -- .</code> 撤销暂存区文件</li><li><code>git reset --hard</code> 清空工作区和暂存区改动</li><li><code>git reset HEAD xxx.txt</code> 放弃 add 到暂存区的指定文件</li></ul><h2 id="定义别名" tabindex="-1"><a class="header-anchor" href="#定义别名" aria-hidden="true">#</a> 定义别名</h2><h3 id="git-配置文件中-gitconfig" tabindex="-1"><a class="header-anchor" href="#git-配置文件中-gitconfig" aria-hidden="true">#</a> git 配置文件中 ~/.gitconfig</h3><div class="language-text line-numbers-mode" data-ext="text"><pre class="language-text"><code>[alias]
   a = add .
   c = commit
   s = status
   l = log
   b = branch
</code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><h3 id="环境变量" tabindex="-1"><a class="header-anchor" href="#环境变量" aria-hidden="true">#</a> 环境变量</h3><blockquote><p>window 修改~/.bashrc 或 ~/.bash_profile。</p><p>mac/linux 修改 ~/.zshrc 文件中定义常用的别名指令，需要首先安装 zsh 命令行扩展</p></blockquote><div class="language-text line-numbers-mode" data-ext="text"><pre class="language-text"><code>alias gs=&quot;git status&quot;
alias gc=&quot;git commit -m &quot;
alias gl=&quot;git log --graph --pretty=format:&#39;%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)&lt;%an&gt;%Creset&#39; --abbrev-commit&quot;
alias gb=&quot;git branch&quot;
alias ga=&quot;git add -A&quot;
alias go=&quot;git checkout&quot;
alias gp=&quot;git push;git push github&quot;
</code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><h2 id="忽略文件-gitignore" tabindex="-1"><a class="header-anchor" href="#忽略文件-gitignore" aria-hidden="true">#</a> 忽略文件 .gitignore</h2><ul><li>所有空行或者以注释符号 <code>＃</code> 开头的行都会被 Git 忽略。</li><li>匹配模式最后跟反斜杠<code>/</code>说明要忽略的是目录。</li><li>glob 模式匹配</li></ul><div class="language-text line-numbers-mode" data-ext="text"><pre class="language-text"><code>.env
/node_modules
/dist
*.txt
</code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><h2 id="暂存-stash" tabindex="-1"><a class="header-anchor" href="#暂存-stash" aria-hidden="true">#</a> 暂存 stash</h2><ul><li><code>git stash</code> 将现有更改暂存</li><li><code>git stash list</code> 查看暂存列表</li><li><code>git stash apply</code> 应用最近的暂存内容</li><li><code>git stash apply stash@{2}</code> 应用更早的暂存内容</li><li><code>git stash drop stash@{0}</code> 删除暂存内容（不推荐）</li><li><code>git stash pop</code> 应用并删除暂存内容（推荐）</li></ul><h2 id="标签-tag" tabindex="-1"><a class="header-anchor" href="#标签-tag" aria-hidden="true">#</a> 标签 Tag</h2><ul><li><code>git tag v1.0</code> 添加标签</li><li><code>git tag</code> 查看所有标签</li><li><code>git push --tags</code> 推送标签</li><li><code>git tag -d v1.0</code> 删除本地仓库标签</li><li><code>git push origin :v1.0</code> 删除远程标签</li></ul><h2 id="打包成-zip" tabindex="-1"><a class="header-anchor" href="#打包成-zip" aria-hidden="true">#</a> 打包成 zip</h2><p>将 master 分支打包成压缩包 <code>git archive master --prefix=&#39;at/&#39; --format=zip &gt; at.zip</code></p><h2 id="ssh-秘钥" tabindex="-1"><a class="header-anchor" href="#ssh-秘钥" aria-hidden="true">#</a> SSH 秘钥</h2><h3 id="生成秘钥" tabindex="-1"><a class="header-anchor" href="#生成秘钥" aria-hidden="true">#</a> 生成秘钥</h3><p>终端输入 <code>ssh-keygen -t rsa</code> 一直回车，会在 <code>~/.ssh</code> 生成<code>id_rsa</code> 秘钥和<code>id_rsa.pub</code> 公钥</p><h2 id="远程仓库" tabindex="-1"><a class="header-anchor" href="#远程仓库" aria-hidden="true">#</a> 远程仓库</h2><ul><li><code>git remote add origin [url]</code> 添加远程仓库地址</li><li><code>git remote -v</code> 查看远程仓库</li><li><code>git remote rm origin</code> 删除远程仓库地址</li><li><code>git remote show origin</code> 查看远程仓库地址</li><li><code>git remote set-url origin [url]</code> 设置远程仓库地址</li></ul><h2 id="pull" tabindex="-1"><a class="header-anchor" href="#pull" aria-hidden="true">#</a> pull</h2><ul><li><code>git pull</code> 同步远程分支代码</li></ul><h2 id="push" tabindex="-1"><a class="header-anchor" href="#push" aria-hidden="true">#</a> push</h2><ul><li><code>git push origin master</code> 推送提交</li></ul></div><!----><footer class="page-meta"><!----><!----><!----></footer><nav class="page-nav"><!----><a href="/doc/sysnotes/Git/%E6%89%A9%E5%B1%95%E4%BD%BF%E7%94%A8.html" class="nav-link next" aria-label="扩展使用"><div class="hint">下一页<span class="arrow right"></span></div><div class="link">扩展使用<!----></div></a></nav><!----><!----><!--]--></main><!--]--><!----><!--]--></div><!--]--><!----><!--]--></div>
    <script type="module" src="/doc/assets/app.41440b49.js" defer></script>
  </body>
</html>
